import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import an49 from '@mmstudio/an000049';
import { Content } from 'antd/lib/layout/layout';
import { message } from 'antd';
import { tbclass, tbcurriculum, tbcurriculums, tbstudent } from '../../../../atoms/db';

const logger = anylogger('pages/api/test.api');

export type Iclass = Pick<ITbclass, 'class_id' | 'classname' | 'major_id' | 'majorname'>[];

export type Result = {
	ok: true;
	data: Pick<ITbcourseassignment, 'jobcontent' | 'jobtitle' | 'job_id' | 'date'>[];
	cas: Pick<ITbclass, 'classname' | 'majorname' | 'class_id'>[];

} | {

	ok: false;
	message: string;

};
export type Message = {

}


/**
 * pages/api/test.api
 */
const handler = an48<Result>();

handler.post(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);

		const db = an49();
		const tb = db<ITbcourseassignment>('courseassignment');
		const teacher_id = 'T001';
		const class_id = await tbcurriculums().distinct('class_id').where({
			teacher_id: teacher_id
		});
		const data = await tb.select('jobcontent', 'jobtitle', 'job_id', 'date').limit(20);

		const class_id1 = class_id.map((it) => {
			return it.class_id;
		});
		const cas = await tbclass().select('majorname', 'classname', 'class_id').whereIn('class_id', class_id1);


		res.status(200).json({
			ok: true,
			data,
			cas,

		});


	} catch (error) {
		logger.trace(error);
		res.status(200).json({
			ok: false,
			message: 'error',

		});
	}
});

export const config = {} as PageConfig;

export default handler;
